<template>

</template>

<script>
import * as echarts from 'echarts';
export default {
  name: "FoldedHistogram",
  mounted() {
    this.initCharts()
  },
  methods: {
    initCharts() {
      var chartDom = document.getElementById('right-top');
      var myChart = echarts.init(chartDom);
      var option;
      $.get(this.$BaseUrl+"/asiangameCountInfo/getall",function(res){
        console.log(res);
        let all=[[],[],[],[]]
        res.forEach((value,index)=>{
          all[0].push(value['goldMedal']);
          all[1].push(value['silverMedal']);
          all[2].push(value['bronzeMedal']);
          all[3].push(value['year'])
        });
        console.log(all);
        option = {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              // Use axis to trigger tooltip
              type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
            }
          },
          legend: {},
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },

          xAxis: {
            type: 'value'
          },
          yAxis: {
            type: 'category',
            data: all[3]
          },
          series: [
            {
              name: '金牌',
              type: 'bar',
              stack: 'total',
              color:"red",
              label: {
                show: true
              },
              emphasis: {
                focus: 'series'
              },
              data:all[0]
            },

            {
              name: '银牌',
              type: 'bar',
              stack: 'total',
              label: {
                show: true
              },
              emphasis: {
                focus: 'series'
              },
              data:all[1]
            },
            {
              name: '铜牌',
              type: 'bar',
              stack: 'total',
              label: {
                show: true
              },
              emphasis: {
                focus: 'series'
              },
              data:all[2]
            }
          ]
        };
        option && myChart.setOption(option);
      })
      window.addEventListener("resize",()=>{
        myChart.resize();
      });



    }
  }
}
</script>

<style scoped>

</style>
